var app = new Vue({
    el: ".withdraw_wrap",
    data() {
        return {
            showaddress: '',
            coinbalcaasdas: '', //输入金额
            Prohibited: false, //禁用按钮多次点击,
            withdrawaddress: '',
            changeaddress: false,
            theuser: '',
            information: '',
            Setup: '設置',
            HPS: {
                free: 12,
                reg: /^0x[A-Za-z0-9]{40}$/
            },
            ETH: {
                free: 0.01,
                reg: /^0x[A-Za-z0-9]{40}$/
            },
            BTC: {
                free: 0.001,
                reg: /^[A-Za-z0-9]{26,34}$/
            },
            HSR: {
                free: 0.1,
                reg: /^[A-Za-z0-9]{30,34}$/
            },
            HAND: {
                free: 30000,
                reg: /^0x[A-Za-z0-9]{40}$/
            },
            HART: {
                free: 70,
                reg: /^0x[A-Za-z0-9]{40}$/
            },
            MOT: {
                free: 12,
                reg: /^0x[A-Za-z0-9]{40}$/
            },
            cointype: ""
        }
    },
    computed: {
        fee: {
            get() {
                let that = this;
                let CoinNumber = this.$refs.coinnumber;
                let amount = this.coinbalcaasdas; //输入的金钱
                if (amount == "" || amount == 0) {
                    amount = 0;
                    return amount;
                }
                let reg = /^\d+\.?(\d{1,4})?$/;
                if (reg.test(amount) == false && amount != "") {
                    amount = 0;
                    that.coinbalcaasdas = "";
                }
                if (amount == "" || amount == null || amount < 0) amount = 0;
                let requiredFee = amount * 0.005; //需要的收费
                let accountBalance = amount - requiredFee; //减去手续费剩下的
                if (requiredFee <= this.$data[this.cointype].free) {
                    if (amount <= 0) {
                        amount = 0;
                    } else {
                        amount = this.$data[this.cointype].free;
                    }
                }
                if (requiredFee > this.$data[this.cointype].free) {
                    amount = amount * (0.005)
                }
                return amount;
            }
        }
    },
    created() {
        let lang = this.getCookie("lang");
        if (lang == "en_US") {
            this.Setup = "Setup";
        } else if (lang == "zh_TW") {
            this.Setup = "設置";
        } else {
            this.Setup = "设置";
        }
        var test = window.location.href;
        let id = test.substring(test.indexOf("id") + 3, test.indexOf("&"));
        let coin = test.substring(test.indexOf("name") + 5)
        this.cointype = coin
    },
    methods: {
        stcAdress(k, index, item) { //设置地址方法
            this.changeaddress = k;
            let lang = this.getCookie("lang");
            let coinValue = document.getElementsByClassName("adressValue" + index)[0].value;
            let coinEle = document.getElementsByClassName("adressValue" + index)[0];
            if (this.changeaddress == false && item != null) {
                let reg = new RegExp(this.$data[this.cointype].reg)
                if (!reg.test(coinValue)) {
                    let timer=setInterval(() => {
                        document.getElementsByClassName('errorMessage')[0].className='errorMessage'
                        clearInterval(timer)
                        timer=null
                    },2000)
                    document.getElementsByClassName('errorMessage')[0].className='errorMessage fadeInUp'
                    if (lang == "en_US") {
                        this.theuser = "Address Error"
                        this.information = "Your withdrawal address is incorrect. Please input again."
                    } else if (lang == "zh_TW") {
                        this.theuser = "地址錯誤"
                        this.information = "您的提現地址设置有誤，請重新輸入"
                    } else {
                        this.theuser = "地址错误"
                        this.information = "您的提现地址输入有误，请重新输入"
                    }
                    return;
                }
                let params = {
                    coin: item,
                    address: coinValue
                };
                axios.post("/adress/coin/withdrawAddress", params).then(res => {
                    if (res.data.code == 200) {
                        this.withdrawaddress = coinValue
                        if (lang == "en_US") {
                            this.Setup = "Modify";
                        } else if (lang == "zh_TW") {
                            this.Setup = "修改";
                        } else {
                            this.Setup = "修改";
                        }
                        let timer=setInterval(() => {
                            document.getElementsByClassName('errorMessage')[0].className='errorMessage'
                            clearInterval(timer)
                            timer=null
                        },2000)
                        document.getElementsByClassName('errorMessage')[0].className='errorMessage fadeInUp'
                        if (lang == "en_US") {
                            this.theuser = "Modify Success"
                            this.information = "Your withdrawal address has been modified successfully."
                        } else if (lang == "zh_TW") {
                            this.theuser = "設置成功"
                            this.information = "您的提現地址設置成功"
                        } else {
                            this.theuser = "设置成功"
                            this.information = "您的提现地址设置成功"
                        }
                    }
                })
            }
        },
        getCookie(cookiename) { //获取cookie
            var arr,
                reg = new RegExp("(^| )" + cookiename + "=([^;]*)(;|$)");
            if ((arr = document.cookie.match(reg))) {
                return unescape(arr[2]);
            } else {
                return null;
            }
        },
        closeinfo() { //关闭弹窗
            let timer=setInterval(() => {
                document.getElementsByClassName('errorMessage')[0].className='errorMessage'
                clearInterval(timer)
                timer=null
            },2000)
            document.getElementsByClassName('errorMessage')[0].className='errorMessage fadeInUp'
            this.theuser = "";
            this.information = ""
            let BODY = document.getElementsByTagName("body")[0]
            BODY.style.overflowY = ""
        },
        cashWidthdraw(index, coin) { //提现金额功能
            let lang = this.getCookie("lang");
            let caasdas = this.coinbalcaasdas; //输入金额
            let blancevalue = document.getElementsByClassName("inpit" + index)[0].value; //币种余额
            let coinValue = document.getElementsByClassName("adressValue" + index)[0].value; //提现地址
            let reg = new RegExp(this.$data[this.cointype].reg)
            if (!reg.test(coinValue)) {
                let timer=setInterval(() => {
                    document.getElementsByClassName('errorMessage')[0].className='errorMessage'
                    clearInterval(timer)
                    timer=null
                },2000)
                document.getElementsByClassName('errorMessage')[0].className='errorMessage fadeInUp'
                if (lang == "en_US") {
                    this.theuser = "Address Error"
                    this.information = "Your withdrawal address is incorrect. Please input again."
                } else if (lang == "zh_TW") {
                    this.theuser = "地址錯誤"
                    this.information = "您的提現地址设置有誤，請重新輸入"
                } else {
                    this.theuser = "地址错误"
                    this.information = "您的提现地址输入有误，请重新输入"
                }
                return;
            }
            let params = {
                coin: coin,
                a: caasdas,
                addr: coinValue
            };
            if (+caasdas > +blancevalue) {
                let timer=setInterval(() => {
                    document.getElementsByClassName('errorMessage')[0].className='errorMessage'
                    clearInterval(timer)
                    timer=null
                },2000)
                document.getElementsByClassName('errorMessage')[0].className='errorMessage fadeInUp'
                if (lang == "en_US") {
                    this.theuser = "Incorrect Amount"
                    this.information = "You cannot enter the amount larger than the account balance."
                } else if (lang == "zh_TW") {
                    this.theuser = "金額錯誤"
                    this.information = "您输入金额不能大于账户余额"
                } else {
                    this.theuser = "金额错误"
                    this.information = "您输入金额不能大于账户余额"
                }
                return;
            } else if (caasdas == '' || caasdas == 0) {
                let timer=setInterval(() => {
                    document.getElementsByClassName('errorMessage')[0].className='errorMessage'
                    clearInterval(timer)
                    timer=null
                },2000)
                document.getElementsByClassName('errorMessage')[0].className='errorMessage fadeInUp'
                if (lang == "en_US") {
                    this.theuser = "Incorrect Amount"
                    this.information = "The amount of input can not be empty or zero."
                } else if (lang == "zh_TW") {
                    this.theuser = "金額錯誤"
                    this.information = "輸入金額不能為空或為零。"
                } else {
                    this.theuser = "金额错误"
                    this.information = "输入金额不能为空或为零。"
                }
                return;
            } else {
                axios.post("/adress/coin/withdraw/", params).then(res => {
                    this.Prohibited = true;
                    if (res.data.code == 200) {
                        this.Prohibited = false;
                        let timer=setInterval(() => {
                            document.getElementsByClassName('errorMessage')[0].className='errorMessage'
                            clearInterval(timer)
                            timer=null
                        },2000)
                        document.getElementsByClassName('errorMessage')[0].className='errorMessage fadeInUp'
                        if (lang == "en_US") {
                            this.theuser = "Successful Application"
                            this.information = "Your application has been successful."
                        } else if (lang == "zh_TW") {
                            this.theuser = "申請成功"
                            this.information = "您的提現申請已成功。"
                        } else {
                            this.theuser = "申请成功"
                            this.information = "您的提现申请已成功。"
                        }
                        location.reload()
                    }else if (res.data.code=-10011){
                        this.Prohibited = false;
                        let timer=setInterval(() => {
                            document.getElementsByClassName('errorMessage')[0].className='errorMessage'
                            clearInterval(timer)
                            timer=null
                        },2000)
                        document.getElementsByClassName('errorMessage')[0].className='errorMessage fadeInUp'
                        if (lang == "en_US") {
                            this.theuser = "Insufficient fee"
                            this.information = "Your fee is insufficient."
                        } else if (lang == "zh_TW") {
                            this.theuser = "手續費不足"
                            this.information = "您的手續費不足。"
                        } else {
                            this.theuser = "手续费不足"
                            this.information = "您的手续费不足。"
                        }
                    }
                })
            }
        },
    }
})